(function() {
  var __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  define(['chaplin', 'views/base/form_view', 'views/base/file_view', 'text!templates/movimento/form.html', 'collections/user_collection', 'lib/enums', 'lib/number_utils'], function(Chaplin, BaseFormView, FileView, Template, UserCollection, Enums, NumberUtils) {
    'use strict';
    var MovimentoFormView, _ref;
    return MovimentoFormView = (function(_super) {
      __extends(MovimentoFormView, _super);

      function MovimentoFormView() {
        _ref = MovimentoFormView.__super__.constructor.apply(this, arguments);
        return _ref;
      }

      MovimentoFormView.prototype.template = Template;

      MovimentoFormView.prototype.validationRules = {
        operacao: {
          required: true
        },
        valor: {
          required: true
        }
      };

      MovimentoFormView.prototype.validatorSettings = {
        ignore: ''
      };

      MovimentoFormView.prototype.afterRender = function() {
        MovimentoFormView.__super__.afterRender.apply(this, arguments);
        return this.setupMasks();
      };

      MovimentoFormView.prototype.setupMasks = function() {
        return this.DOMElements.$valor.setMask('decimal');
      };

      MovimentoFormView.prototype.cacheDOMElements = function() {
        return _.extend(MovimentoFormView.__super__.cacheDOMElements.apply(this, arguments), {
          $operacao: this.$('[name="operacao"]'),
          $observacao: this.$('[name="observacao"]'),
          $valor: this.$('[name="valor"]')
        });
      };

      MovimentoFormView.prototype.getTemplateData = function() {
        return _.extend(MovimentoFormView.__super__.getTemplateData.apply(this, arguments), {
          tipoOperacao: Enums.tipoOperacao
        });
      };

      MovimentoFormView.prototype.fillForm = function() {
        this.DOMElements.$operacao.val(this.model.get('operacao'));
        this.DOMElements.$observacao.val(this.model.get('observacao'));
        return this.DOMElements.$valor.val(this.setDecimal(this.model.get('valor')));
      };

      MovimentoFormView.prototype.fillModel = function() {
        return this.model.set({
          operacao: this.DOMElements.$operacao.val(),
          observacao: this.DOMElements.$observacao.val(),
          valor: this.fixDecimal(this.DOMElements.$valor.val())
        });
      };

      MovimentoFormView.prototype.saveData = function() {
        return MovimentoFormView.__super__.saveData.apply(this, arguments);
      };

      MovimentoFormView.prototype.setDecimal = function(val) {
        if (val) {
          return NumberUtils.number_format(val, 2, ',', '.');
        } else {
          return '0,00';
        }
      };

      MovimentoFormView.prototype.fixDecimal = function(val) {
        if (val == null) {
          val = '';
        }
        return val.replace(/\./g, '').replace(',', '.');
      };

      return MovimentoFormView;

    })(BaseFormView);
  });

}).call(this);
